import Vue from "vue";
import VueRouter from "vue-router";
import store from "@/store";
Vue.use(VueRouter);
import "@/assets/styles/index.scss"; // global css
import login from "@/views/login.vue";

const routes = [
  { path: "/", redirect: "/login" },
  { path: "/login", name: "login", component: login },
  {
    path: "/index",
    name: "index",
    
    component: () => import("@/layout/index.vue"),
    children: [
      {
        path: "",
        redirect: "index/dashboard",
      },
      // 控制台
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/dashboard.vue"),
        meta: {
          title: "控制台",
          icon: "el-icon-monitor",
          type: "0",
          index: "/index/dashboard",
        },
      },
      // 实验室管理模块下：
      // 化验工单管理
      {
        path: "labWorkOrder",
        name: "labWorkOrder",
        component: () => import("@/views/labManagement/labWorkOrder.vue"),
        meta: {
          title: "化验工单管理",
          icon: "el-icon-monitor",
          type: "5",
          index: "/index/labWorkOrder",
        },
      },
    
      // 设备管理
      {
        path: "deviceManagement",
        name: "deviceManagement",
        component: () =>
          import("@/views/deviceManagement/deviceManagement.vue"),
        meta: {
          title: "设备管理",
          icon: "el-icon-monitor",
          type: "6",
          index: "/index/deviceManagement",
        },
      },
      {
        path: "deviceReceive",
        name: "deviceReceive",
        component: () => import("@/views/deviceManagement/deviceReceive.vue"),
        meta: { title: "设备接收", type: "6", index: "/index/deviceReceive" },
      },
      {
        path: "deviceRepair",
        name: "deviceRepair",
        component: () => import("@/views/deviceManagement/deviceRepair.vue"),
        meta: { title: "设备维修", type: "6", index: "/index/deviceRepair" },
      },
      {
        path: "deviceMaintenance",
        name: "deviceMaintenance",
        component: () =>
          import("@/views/deviceManagement/deviceMaintenance.vue"),
        meta: {
          title: "设备保养",
          type: "6",
          index: "/index/deviceMaintenance",
        },
      },
      {
        path: "deviceScrap",
        name: "deviceScrap",
        component: () => import("@/views/deviceManagement/deviceScrap.vue"),
        meta: { title: "设备报废", type: "6", index: "/index/deviceScrap" },
      },
      {
        path: "templateManagement",
        name: "templateManagement",
        component: () =>
          import("@/views/deviceManagement/templateManagement.vue"),
        meta: {
          title: "模版管理",
          type: "6",
          index: "/index/templateManagement",
        },
      },
      {
        path: "netValueManagement",
        name: "netValueManagement",
        component: () =>
          import("@/views/deviceManagement/netValueManagement.vue"),
        meta: {
          title: "净值管理",
          type: "6",
          index: "/index/netValueManagement",
        },
      },
      {
        path: "add",
        name: "add",
        component: () => import("@/views/deviceManagement/add.vue"),
      },
    ],
  },
];

const router = new VueRouter({
  mode: "history",
  routes,
});
router.beforeEach((to, from, next) => {
  console.log("to:", to);
  console.log("from:", from);
  const path = to.path;
  const regex = /^\/index\//;
  if (path === "/login") {
     store.commit('resetTopTabbar');
  }
  if (regex.test(path)) {
    store.commit("updataTopTabbar", {
      name: to.path,
      title: to.meta.title,
    });
  }
  next();
});
export default router;
